package csl.blog.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import csl.blog.common.entity.Permission;
import csl.blog.server.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @author: 隔山海
 */
@RequestMapping("permission")
@RestController
@Slf4j
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public boolean add(@RequestBody Permission permission){
        permission.setPermissionId(String.valueOf(IdWorker.getId()));
       return permissionService.save(permission);
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    public List<Permission> queryByCondition(@RequestBody Permission permission){
        LambdaQueryWrapper<Permission> query = new LambdaQueryWrapper<>();
        query.eq(Permission::getPermissionId,permission.getPermissionId());
        return permissionService.list(query);
    }
}
